<div class="layui-fluid" >
    <div class="layui-card">
        <div class="layui-card-body" style="padding: 15px;">
            <form class="layui-form" action="" lay-filter="addForm">
                <div class="layui-form-item">
                    <label class="layui-form-label"><span style="color: red">*</span>角色名称</label>
                    <div class="layui-input-block">
                        <input type="text" name="roleName" lay-verify="required" autocomplete="off" placeholder="请输入角色名称" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">备注</label>
                    <div class="layui-input-block">
                        <input type="text" name="remark" placeholder="请输入" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <div class="layui-input-block">
                        <a class="layui-btn" lay-submit="" lay-filter="addRoleSubmit">立即提交</a>
                        <a class="layui-btn layui-btn-primary" id="close">关闭</a>
                    </div>
                </div>
            </form>
        </div>
    </div>
</div>

<script>
    var AddRole = function (admin,form,layer, index,$) {
        //初始化
        this.init = function () {
            /* 监听提交 */
            form.on('submit(addRoleSubmit)', function (data) {
                var requestData = data.field;
                //提交用户
                admin.post({
                    api:'saveRole',
                    data:JSON.stringify(requestData),
                    contentType: 'application/json;charset=UTF-8',
                    success:function (res) {
                        if(res.code == 0){
                            admin.success('操作成功',function () {
                                parent.roleList.refresh();
                                parent.layer.close(index);
                            });
                        }
                    }
                });
                return false;
            });
            //关闭窗口
            $("#close").click(function () {
                parent.layer.close(index);
            });
        };
    };

</script>